package com.fsnbigdata.domain;

import com.fsnbigdata.util.ChineseInital;
import io.springlets.format.EntityFormat;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Version;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.Index;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.roo.addon.javabean.annotations.RooEquals;
import org.springframework.roo.addon.javabean.annotations.RooJavaBean;
import org.springframework.roo.addon.javabean.annotations.RooToString;
import org.springframework.roo.addon.jpa.annotations.entity.JpaRelationType;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaRelation;
import org.springframework.util.Assert;

/**
 * = Vegetation
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJavaBean
@RooToString
@RooJpaEntity(entityFormatExpression = "#{location}")
@RooEquals(isJpaEntity = true)
@Entity
@EntityFormat("#{location}")
public class Vegetation {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Version
    private Integer version;

    /**
     * 名称
     */
    @NotNull(message = "植被名称不能为空")
    @Length(min=1,max=255,message="植被名称必须在1-255之间")
    private String name;

    /**
     * 拼音首字母
     */
    @Index(name="Vegetation_initial")
    private String initial;

    /**
     * 建群种_乔木层
     */
    @Length(min=0,max=255,message="植被建群种_乔木层长度必须在0-255之间")
    private String edificationAName;

    /**
     * 建群种_乔木层
     */
    @Length(min=0,max=255,message="植被建群种_乔木层长度必须在0-255之间")
    private String edificationALatin;

    /**
     * 生物id
     */
    @NumberFormat
    private Long edificationAOrganismId;

    /**
     * 建群种_灌木层
     */
    @Length(min=0,max=255,message="植被建群种_灌木层长度必须在0-255之间")
    private String edificationBName;

    /**
     * 建群种_灌木层
     */
    @Length(min=0,max=255,message="植被建群种_灌木层长度必须在0-255之间")
    private String edificationBLatin;

    /**
     * 生物id
     */
    @NumberFormat
    private Long edificationBOrganismId;

    /**
     * 建群种_草本层
     */
    @Length(min=0,max=255,message="植被建群种_草本层长度必须在0-255之间")
    private String edificationCName;

    /**
     * 建群种_灌木层
     */
    @Length(min=0,max=255,message="植被建群种_灌木层长度必须在0-255之间")
    private String edificationCLatin;

    /**
     * 生物id
     */
    @NumberFormat
    private Long edificationCOrganismId;

    /**
     * 分类类型_自然,人工植被
     */
    @Length(min=0,max=255,message="植被建群种_灌木层长度必须在0-255之间")
    private String category;

    /**
     * 分类类型_植被型组
     */
    @Length(min=0,max=255,message="植被分类类型_植被型组长度必须在0-255之间")
    private String categoryA1;

    /**
     * 分类类型_植被型（亚型）
     */
    @Length(min=0,max=255,message="植被分类类型_植被型（亚型）长度必须在0-255之间")
    private String categoryA2;

    /**
     * 分类类型_群系组
     */
    @Length(min=0,max=255,message="植被分类类型_群系组长度必须在0-255之间")
    private String categoryA3;

    /**
     * 分类类型_群系
     */
    @Length(min=0,max=255,message="植被分类类型_群系长度必须在0-255之间")
    private String categoryA4;

    /**
     * 分类类型_亚群系
     */
    @Length(min=0,max=255,message="植被分类类型_亚群系长度必须在0-255之间")
    private String categoryA5;

    /**
     * 分类类型_群丛
     */
    @Length(min=0,max=255,message="植被分类类型_群丛长度必须在0-255之间")
    private String categoryA6;

    /**
     * 分类类型_植被类型
     */
    @Length(min=0,max=255,message="植被分类类型_植被类型长度必须在0-255之间")
    private String categoryB1;

    /**
     * 分类类型_植被型
     */
    @Length(min=0,max=255,message="植被分类类型_植被型长度必须在0-255之间")
    private String categoryB2;

    /**
     * 分类类型_植被亚型
     */
    @Length(min=0,max=255,message="植被分类类型_植被亚型长度必须在0-255之间")
    private String categoryB3;

    /**
     * 分类类型_植被组合型
     */
    @Length(min=0,max=255,message="植被分类类型_植被组合型长度必须在0-255之间")
    private String categoryB4;

    /**
     * 生境特点_海拔
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String habitatAltitude;

    /**
     * 生境特点_土壤类型
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String habitatAgrotype;

    /**
     * 生境特点_温度
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String habitatTemperature;

    /**
     * 生境特点_降水量
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String habitatPrecipitation;

    /**
     * 群落特征
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String communityCharacteristics;

    /**
     * 创建者
     */
    @Length(min=0,max=255,message="植被创建者长度必须在0-255之间")
    private String creator;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "vegetation", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("country, province, city")
    @Valid
    private Set<VegetationDistribution> distribution = new HashSet<VegetationDistribution>();

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "vegetation", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("id")
    @Valid
    private Set<VegetationImage> images = new HashSet<VegetationImage>();

    /**
     * 样方表
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "vegetation", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("quadratYear")
    @Valid
    private Set<ListQuadrat> listQuadrat = new HashSet<ListQuadrat>();

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * This `equals` implementation is specific for JPA entities and uses
     * the entity identifier for it, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @param obj
     * @return Boolean
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // instanceof is false if the instance is null
        if (!(obj instanceof Vegetation)) {
            return false;
        }
        return getId() != null && Objects.equals(getId(), ((Vegetation) obj).getId());
    }

    /**
     * This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able
     * to identify the entity in collections after a new id is assigned to the entity, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @return Integer
     */
    public int hashCode() {
        return 31;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getId() {
        return this.id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Integer
     */
    public Integer getVersion() {
        return this.version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param version
     */
    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getName() {
        return this.name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getInitial() {
        return this.initial;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param initial
     */
    public void setInitial(String initial) {
        this.initial = initial;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationAName() {
        return this.edificationAName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationAName
     */
    public void setEdificationAName(String edificationAName) {
        this.edificationAName = edificationAName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationALatin() {
        return this.edificationALatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationALatin
     */
    public void setEdificationALatin(String edificationALatin) {
        this.edificationALatin = edificationALatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getEdificationAOrganismId() {
        return this.edificationAOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationAOrganismId
     */
    public void setEdificationAOrganismId(Long edificationAOrganismId) {
        this.edificationAOrganismId = edificationAOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationBName() {
        return this.edificationBName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationBName
     */
    public void setEdificationBName(String edificationBName) {
        this.edificationBName = edificationBName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationBLatin() {
        return this.edificationBLatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationBLatin
     */
    public void setEdificationBLatin(String edificationBLatin) {
        this.edificationBLatin = edificationBLatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getEdificationBOrganismId() {
        return this.edificationBOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationBOrganismId
     */
    public void setEdificationBOrganismId(Long edificationBOrganismId) {
        this.edificationBOrganismId = edificationBOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationCName() {
        return this.edificationCName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationCName
     */
    public void setEdificationCName(String edificationCName) {
        this.edificationCName = edificationCName;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getEdificationCLatin() {
        return this.edificationCLatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationCLatin
     */
    public void setEdificationCLatin(String edificationCLatin) {
        this.edificationCLatin = edificationCLatin;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getEdificationCOrganismId() {
        return this.edificationCOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param edificationCOrganismId
     */
    public void setEdificationCOrganismId(Long edificationCOrganismId) {
        this.edificationCOrganismId = edificationCOrganismId;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategory() {
        return this.category;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param category
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA1() {
        return this.categoryA1;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA1
     */
    public void setCategoryA1(String categoryA1) {
        this.categoryA1 = categoryA1;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA2() {
        return this.categoryA2;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA2
     */
    public void setCategoryA2(String categoryA2) {
        this.categoryA2 = categoryA2;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA3() {
        return this.categoryA3;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA3
     */
    public void setCategoryA3(String categoryA3) {
        this.categoryA3 = categoryA3;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA4() {
        return this.categoryA4;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA4
     */
    public void setCategoryA4(String categoryA4) {
        this.categoryA4 = categoryA4;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA5() {
        return this.categoryA5;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA5
     */
    public void setCategoryA5(String categoryA5) {
        this.categoryA5 = categoryA5;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryA6() {
        return this.categoryA6;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryA6
     */
    public void setCategoryA6(String categoryA6) {
        this.categoryA6 = categoryA6;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryB1() {
        return this.categoryB1;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryB1
     */
    public void setCategoryB1(String categoryB1) {
        this.categoryB1 = categoryB1;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryB2() {
        return this.categoryB2;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryB2
     */
    public void setCategoryB2(String categoryB2) {
        this.categoryB2 = categoryB2;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryB3() {
        return this.categoryB3;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryB3
     */
    public void setCategoryB3(String categoryB3) {
        this.categoryB3 = categoryB3;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategoryB4() {
        return this.categoryB4;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param categoryB4
     */
    public void setCategoryB4(String categoryB4) {
        this.categoryB4 = categoryB4;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getHabitatAltitude() {
        return this.habitatAltitude;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param habitatAltitude
     */
    public void setHabitatAltitude(String habitatAltitude) {
        this.habitatAltitude = habitatAltitude;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getHabitatAgrotype() {
        return this.habitatAgrotype;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param habitatAgrotype
     */
    public void setHabitatAgrotype(String habitatAgrotype) {
        this.habitatAgrotype = habitatAgrotype;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getHabitatTemperature() {
        return this.habitatTemperature;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param habitatTemperature
     */
    public void setHabitatTemperature(String habitatTemperature) {
        this.habitatTemperature = habitatTemperature;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getHabitatPrecipitation() {
        return this.habitatPrecipitation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param habitatPrecipitation
     */
    public void setHabitatPrecipitation(String habitatPrecipitation) {
        this.habitatPrecipitation = habitatPrecipitation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCommunityCharacteristics() {
        return this.communityCharacteristics;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param communityCharacteristics
     */
    public void setCommunityCharacteristics(String communityCharacteristics) {
        this.communityCharacteristics = communityCharacteristics;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCreator() {
        return this.creator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param creator
     */
    public void setCreator(String creator) {
        this.creator = creator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<VegetationDistribution> getDistribution() {
        return this.distribution;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param distribution
     */
    public void setDistribution(Set<VegetationDistribution> distribution) {
        this.distribution = distribution;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<VegetationImage> getImages() {
        return this.images;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param images
     */
    public void setImages(Set<VegetationImage> images) {
        this.images = images;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<ListQuadrat> getListQuadrat() {
        return this.listQuadrat;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadrat
     */
    public void setListQuadrat(Set<ListQuadrat> listQuadrat) {
        this.listQuadrat = listQuadrat;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String toString() {
        return "Vegetation {" + "id='" + id + '\'' + ", version='" + version + '\'' + ", name='" + name + '\'' + ", initial='" + initial + '\'' + ", edificationAName='" + edificationAName + '\'' + ", edificationALatin='" + edificationALatin + '\'' + ", edificationAOrganismId='" + edificationAOrganismId + '\'' + ", edificationBName='" + edificationBName + '\'' + ", edificationBLatin='" + edificationBLatin + '\'' + ", edificationBOrganismId='" + edificationBOrganismId + '\'' + ", edificationCName='" + edificationCName + '\'' + ", edificationCLatin='" + edificationCLatin + '\'' + ", edificationCOrganismId='" + edificationCOrganismId + '\'' + ", category='" + category + '\'' + ", categoryA1='" + categoryA1 + '\'' + ", categoryA2='" + categoryA2 + '\'' + ", categoryA3='" + categoryA3 + '\'' + ", categoryA4='" + categoryA4 + '\'' + ", categoryA5='" + categoryA5 + '\'' + ", categoryA6='" + categoryA6 + '\'' + ", categoryB1='" + categoryB1 + '\'' + ", categoryB2='" + categoryB2 + '\'' + ", categoryB3='" + categoryB3 + '\'' + ", categoryB4='" + categoryB4 + '\'' + ", habitatAltitude='" + habitatAltitude + '\'' + ", habitatAgrotype='" + habitatAgrotype + '\'' + ", habitatTemperature='" + habitatTemperature + '\'' + ", habitatPrecipitation='" + habitatPrecipitation + '\'' + ", communityCharacteristics='" + communityCharacteristics + '\'' + ", creator='" + creator + '\'' + ", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' + ", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' + "}" + super.toString();
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param distributionToAdd
     */
    public void addToDistribution(Iterable<VegetationDistribution> distributionToAdd) {
        Assert.notNull(distributionToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (VegetationDistribution item : distributionToAdd) {
            this.distribution.add(item);
            item.setVegetation(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param distributionToRemove
     */
    public void removeFromDistribution(Iterable<VegetationDistribution> distributionToRemove) {
        Assert.notNull(distributionToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (VegetationDistribution item : distributionToRemove) {
            this.distribution.remove(item);
            item.setVegetation(null);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToAdd
     */
    public void addToImages(Iterable<VegetationImage> imagesToAdd) {
        Assert.notNull(imagesToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (VegetationImage item : imagesToAdd) {
            this.images.add(item);
            item.setVegetation(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToRemove
     */
    public void removeFromImages(Iterable<VegetationImage> imagesToRemove) {
        Assert.notNull(imagesToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (VegetationImage item : imagesToRemove) {
            this.images.remove(item);
            item.setVegetation(null);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadratToAdd
     */
    public void addToListQuadrat(Iterable<ListQuadrat> listQuadratToAdd) {
        Assert.notNull(listQuadratToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (ListQuadrat item : listQuadratToAdd) {
            this.listQuadrat.add(item);
            item.setVegetation(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadratToRemove
     */
    public void removeFromListQuadrat(Iterable<ListQuadrat> listQuadratToRemove) {
        Assert.notNull(listQuadratToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (ListQuadrat item : listQuadratToRemove) {
            this.listQuadrat.remove(item);
            item.setVegetation(null);
        }
    }

    @PrePersist
    public void prePersist(){
        this.setInitial(ChineseInital.getFirstLetter(this.getName()));
    }

    @PreUpdate
    public void preUpdate(){
        this.setInitial(ChineseInital.getFirstLetter(this.getName()));
    }
}
